package arithmetic;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Btest {
    /**
     * 给定两个字符串 s 和 t ，只包含小写字母。
     * t 由 s 随机重排，在t的随机位置添加一个字母，请找出在 t 中被添加的字母。
     *
     * @param args
     */
    public static void main(String[] args) {

        String s = "aassdd";
        String t = "aasswdd";
        char result = demo1(s, t);
        System.out.println(result);

    }


    public static char demo1(String s, String t) {

        StringBuffer stringBuffer = new StringBuffer(s);
//        String.
        char[] chars = s.toCharArray();
        char[] chars2 = t.toCharArray();
        /**
         *
         */
//        char[] chs = paixu(chars);
//        char[] cht = paixu(chars2);

        char[] chs = chars;
        char[] cht = chars2;

        Arrays.sort(chs);
        Arrays.sort(cht);

        char result = 'a';

        for (int i = 0; i < cht.length; i++) {
            char t1 = cht[i];
            if (i >= chs.length) {
                result = t1;
                break;
            }
            else{
                char s1 = chs[i];
                if (s1 != t1) {
                    result = t1;
                    break;
                }
            }
        }
        return result;


    }

    /**
     * 排序
     */
    public static char[] paixu(char[] chars) {
//        char[] ch2 = new char[chars.length];
//        System.out.println(ch2.toS);
        for (int i = 0; i < chars.length; i++) {
            char a = chars[i];
            int j = i + 1;
            while (j < chars.length) {
                char b = chars[j];
                char temp = 'a';
                if (a > b) {
                    temp = a;
                    chars[i] = b;
                    chars[j] = temp;
                }
                j++;
            }
        }
        return chars;
    }
}
